<!doctype html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
	<title>后台登录-X-admin2.2</title>
	<header th:replace="sys/head :: head " />
    <link rel="stylesheet" th:href="@{/X-admin/css/login.css}">

</head>
<body class="login-bg">
    
    <div class="login layui-anim layui-anim-up">
        <div class="message">Z 管理登录</div>
        <div id="darkbannerwrap"></div>
        
        <form method="post" class="layui-form" >
            <input name="username" placeholder="用户名"  type="text" lay-verify="required" class="layui-input" >
            <hr class="hr15">
            <input name="password" lay-verify="required" placeholder="密码"  type="password" class="layui-input">
            <hr class="hr15">
            <input value="登录" lay-submit lay-filter="login" style="width:100%;" type="submit">
            <hr class="hr20" >
        </form>
    </div>

    <script>
        $(function  () {
            layui.use('form', function(){
              var form = layui.form;
              //监听提交
              form.on('submit(login)', function(data){
                $.ajax({
                    url: appPath + '/login',
                    type: 'post',
                    data: data.field,
                    success: function (datas) {
                        if(datas.authenticated == true){
                            localStorage.setItem("userId", datas.principal.id);
                            localStorage.setItem("nickName", datas.principal.nickname);
                            var authorites = datas.authorities;
                            var permission = [];
                            for(var i in authorites){
                                permission.push(authorites[i].authority);
                            }
                            localStorage.setItem("permission", JSON.stringify(permission));
                            layer.msg("登录成功",{time:500},function () {
                                top.window.location = appPath;
                            })

                        }else{
                            layer.msg("登录异常，联系管理员");
                        }

                    },
                    error: function (xhr, testStatus, errorThrown) {
                        var msg = xhr.responseText;
                        var response = JSON.parse(msg);
                        layer.msg(response.message);
                    }
                });
                return false;
              });
            });
        })
    </script>
    <!-- 底部结束 -->

</body>
</html>